package com.thundersoft.musicplayer.Collector;

import android.app.Activity;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: liuzh0705
 * @Date:2021/07/27/下午5:04
 * @Description: 管理活动
 */
public class ActivityCollector {
    // 管理activity的集合
    public static List<Activity> activities = new ArrayList<>();

    /**
     * 添加Activity到集合中
     * @param activity
     */
    public static void addActivity(Activity activity) {
        activities.add(activity);
    }

    /**
     * 从集合中删除Activity
     * @param activity
     */
    public static void removeActivity(Activity activity) {
        activities.remove(activity);
    }

    /**
     * 销毁所有的Activity
     */
    public static void finishAll() {
        for (Activity activity : activities) {
            if (!activity.isFinishing()) {
                activity.finish();
            }
        }
        activities.clear();
    }

}
